/* vim: set sw=8 ts=8 sts=8 expandtab: */
#include "Cmaid.h"
#include "cmaid_private.h"
#include <stdio.h>

/**
 * @param iter to check
 * @return Returns no value
 *
 * This function will abort the whole process if the given iterator is not
 * detached from its container. The function is mainly used for
 * __CMAID_CHECKED_ITER__.
 */
EAPI void
cmaid_magic_iter_check(Cmaid_Iter *iter)
{
        if (iter->interface != NULL || iter->container != NULL)
        {
                fprintf(stderr, "Cmaid Warning! Iter %p is still attached!\n",
                                iter);
                /* this is normally critical, abort before the system will
                   do it */
                abort();
        }
}

/**
 * @param type The type to be checked
 * @param func The function where the check occures
 * @param par The invalid parameter
 * @return Returns no value
 *
 * This function will print a warning that the given @p par does not match
 * the type @p type called in the function @p func. If @p type equals @c NULL
 * a pointer check to @c NULL instead of a type check is assumed.
 */
EAPI void
cmaid_magic_warning_print(const char *type, const char *func, const char *par)
{
        if (!type)
                fprintf(stderr, "*** Cmaid Warning ***\n\n"
                                "\t%s();\n\n"
                                "\tWith the parameter %s"
                                "being NULL.\n\n"
                                "Please fix your program."
                                "To find where your program failed set a"
                                " breakpoint at\t\n%s\n",
                        func, par, __func__);
        else
                 fprintf(stderr, "*** Cmaid Warning ***\n\n"
                                 "\t%s();\n\n"
                                 "\tWith the parameter %s"
                                 "is not of the type \'%s\'.\n\n"
                                 "Please fix your program.\n"
                                 "To find where your program failed set a"
                                 " breakpoint at\t\n%s\n",
                        func, par, type, __func__);
}

